//
//  GMWaterMarkView.m
//  SplunkMobile
//
//  Created by i.Recall_Star on 2017/6/2.
//  Copyright © 2017年 Gome. All rights reserved.
//

#define ALPHAVALUE 0.15
#define TRANSFORM 0.5
#import "Conifg.h"

#import "GMWaterMarkView.h"
@interface GMWaterMarkView()
{
    NSMutableArray *_viewArray;
}

@end
@implementation GMWaterMarkView
static GMWaterMarkView* _instance = nil;

+ (instancetype) shareInstance
{
    static dispatch_once_t onceToken ;
    dispatch_once(&onceToken, ^{
        _instance = [[GMWaterMarkView alloc] init] ;
    }) ;
    return _instance ;
}

- (id)init
{
    self = [super init];
    if (self){
        self.backgroundColor = [UIColor clearColor];
        _viewArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return self;
}

- (void)setFrame:(CGRect)frame
{
    for (int j = 0; j < 2; j++){
        for (int i = 0; i < 2; i++){
            float height = 150;
            float top = 130;
            float offSetX = 90;
            float offSetY = 40;
            float y = top + ((frame.size.height - height * 2 - top)+height - offSetY)*j;
            UILabel *infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(i * frame.size.width/2-offSetX, y, frame.size.width, height)];
            infoLabel.textAlignment = NSTextAlignmentCenter;
            infoLabel.numberOfLines = 0;
            infoLabel.textColor = [UIColor grayColor];
            infoLabel.alpha = 0.2;
            infoLabel.backgroundColor = [UIColor clearColor];
            infoLabel.text = [NSString stringWithFormat:@"国美互联网 \n 持有人： \n %@", [self getCurrentTime]];
            infoLabel.transform = CGAffineTransformMakeRotation(TRANSFORM);
            [self addSubview:infoLabel];
            [_viewArray addObject:infoLabel];
        }
    }
}

- (NSString *) getCurrentTime
{
    NSDate *date = [NSDate date];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  
    [formatter setDateFormat:@"YYYY年MM月dd日 HH:mm:ss"];
    
    NSString *DateTime = [formatter stringFromDate:date];
    return DateTime;
}
- (void)showTheWaterMark
{
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    NSString *userName = [userDefault objectForKey:@"splunk_userName"];
    for (int i = 0; i < _viewArray.count; i++) {
        UILabel *label = [_viewArray objectAtIndex:i];
        label.text = [NSString stringWithFormat:@"国美互联网 \n 持有人：%@ \n %@", GMK_Str_Protect(userName), [self getCurrentTime]];
    }
}

- (void)hidenTheWaterMark
{
    for (int i = 0; i < _viewArray.count; i++) {
        UILabel *label = [_viewArray objectAtIndex:i];
        label.text = [NSString stringWithFormat:@"国美互联网 \n 持有人： \n %@", [self getCurrentTime]];
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
